//
//  UIBarButtonItem+Extension.m
//  iBook
//
//  Created by wangjing on 14/12/4.
//  Copyright (c) 2014年 wikiflyer. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"
#import "UIImage+Extension.h"
#import "UIView+Extension.h"

@implementation UIBarButtonItem (Extension)

+(UIBarButtonItem *)itemWithImageName:(NSString *)imageName highImageName:(NSString *)highImageName target:(id)target action:(SEL)action{
    UIButton *btn = [[UIButton alloc]init];
    
    UIImage *normalImage = [UIImage imageWithName:imageName];
    UIImage *highImage = [UIImage imageWithName:highImageName];
    //设置按钮的背景图片(默认/高亮)
    [btn setBackgroundImage:normalImage forState:UIControlStateNormal];
    [btn setBackgroundImage:highImage forState:UIControlStateHighlighted];
    
    //设置按钮的尺寸和图片一样大,使用了UIImage的分类
    btn.size = btn.currentBackgroundImage.size;
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc]initWithCustomView:btn];
}

@end
